package com.lyy.config;

import com.lyy.component.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Liangyaoyun
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {


    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 将自定义拦截器注册到全局拦截器链中
        registry.addInterceptor(tokenInterceptor)
                // 拦截所有 `/api/v1/**` 请求
                .addPathPatterns("/api/v1/**")
                // 放行部分不需要Token验证的请求
                .excludePathPatterns("/api/v1/user/loginByAccount",
                        "/api/v1/user/loginByPhone",
                        "/api/v1/user/generateVcode",
                        "/api/v1/user/register",
                        "/api/v1/banner/list/*",
                        "/api/v1/video/selectByVideoId/*",
                        "/api/v1/video/searchByVideoTitle");
    }
}
